home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / c-runtime / dispatch / mutex.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-18  |  3.2 KB  |  125 lines

  1. /* -*-c-*- */
  2.  
  3. /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* As a special exception, if you link this library with files
  22.    compiled with GCC to produce an executable, this does not cause
  23.    the resulting executable to be covered by the GNU General Public License.
  24.    This exception does not however invalidate any other reasons why
  25.    the executable file might be covered by the GNU General Public License.  */
  26.  
  27. /* 
  28.   $Header: /usr/user/dennis_glatting/ObjC/c-runtime/dispatch/RCS/mutex.h,v 1.3 1992/08/18 04:46:58 dglattin Exp $
  29.   $Author: dglattin $
  30.   $Date: 1992/08/18 04:46:58 $
  31.   $Log: mutex.h,v $
  32.  * Revision 1.3  1992/08/18  04:46:58  dglattin
  33.  * Saving a working version before release.
  34.  *
  35.  * Revision 1.2  1992/04/13  11:43:08  dennisg
  36.  * Check in after array version of run-time works.
  37.  * Expect more changes as hash version and other changes are made.
  38.  *
  39.  * Revision 1.1  1991/12/09  01:07:13  dennisg
  40.  * Initial revision
  41.  *
  42. */
  43.  
  44.  
  45. #ifndef _MUTEX_H
  46. #define _MUTEX_H
  47.  
  48. #ifdef WANT_MUTEX
  49. #if defined(NeXT)
  50. #include  <cthreads.h>
  51. #define MUTEX               mutex_t
  52. #define MUTEX_ALLOC(mutex)  { *mutex = mutex_alloc(); }
  53. #define MUTEX_INIT(mutex)   mutex_init(mutex)
  54. #define MUTEX_FREE(mutex)   mutex_free(mutex)
  55. #define MUTEX_LOCK(mutex)   mutex_lock(mutex)
  56. #define MUTEX_UNLOCK(mutex) mutex_unlock(mutex)
  57. #define MUTEX_ISLOCK(mutex)     mutex->lock /* Gak */
  58.  
  59. #elif defined(OSF)
  60.  
  61. #elif defined(mach)
  62.  
  63. #elif defined(sun)
  64. /*
  65.  * Sun lwp uses monitors.
  66.  *
  67.  * Untested.  8-Dec-91, dennisg.
  68.  */
  69. #include  <lwp/lwp.h>
  70. #include  <assert.h>
  71. #define MUTEX               (mon_t)
  72. inline MUTEX
  73. MUTEX_ALLOC(mutex) {
  74.  
  75.   MUTEX mon;
  76.   
  77.   mon_create (&mon);
  78.   return mon;
  79. }
  80. #define MUTEX_INIT(mutex)
  81. #define MUTEX_FREE(mutex)   mon_destroy(mutex)
  82. inline void
  83. MUTEX_LOCK(mutex) {
  84.  
  85.   int nestingLevel = mon_enter(mutex);
  86.   assert(nestingLevel);
  87. }
  88. #define MUTEX_UNLOCK(mutex) mon_exit(mutex)
  89. inline int
  90. MUTEX_ISLOCK(mutex) {
  91.  
  92.         thread_t        aThread;
  93.  
  94.         /* Won't work? */
  95.         return mon_waiters( mutex, &aThread, NULL, 0);
  96. }
  97.  
  98. #elif defined(COROUTINES)
  99. /*
  100.  * A environment where threads are implemented as a
  101.  *  set of coroutines.
  102.  */
  103.  
  104. #endif
  105. #endif
  106.  
  107. #ifndef MUTEX
  108. /*
  109.  * These are default mutex handler routines.
  110.  *  There is no mutex support.
  111.  *
  112.  * Let the optimizer get rid of mutexes.
  113.  */
  114.  
  115. #define MUTEX void*
  116. #define MUTEX_ALLOC(mutex)  (MUTEX)-1
  117. #define MUTEX_INIT(mutex)               (mutex)
  118. #define MUTEX_FREE(mutex)               (mutex)
  119. #define MUTEX_LOCK(mutex)               (mutex)
  120. #define MUTEX_UNLOCK(mutex)     (mutex)
  121. #define MUTEX_ISLOCK(mutex)     1
  122. #endif
  123.  
  124. #endif
  125.